package com.hntxk.cqzd.diacrisis.service.impl;

import com.hntxk.core.framework.service.impl.BaseServiceImpl;
import com.hntxk.cqzd.common.service.CommonFileService;
import com.hntxk.cqzd.diacrisis.entity.TblDiacrisisFile;
import com.hntxk.cqzd.diacrisis.model.DiacrisisAllModel;
import com.hntxk.cqzd.diacrisis.service.DiacrisisFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service("diacFileService")
@Transactional(rollbackFor = Exception.class)
public class DiacrisisFileServiceImpl extends BaseServiceImpl<TblDiacrisisFile> implements DiacrisisFileService {

    @Autowired
    @Qualifier("commonFileServiceImpl")
    private CommonFileService commonFileService;

    public static String DIACFILE_MAPPER_NAMESPACE="com.hntxk.cqzd.diacrisis.mapper.DiacrisisFileMapper.";

    public DiacrisisFileServiceImpl() {
        super(DIACFILE_MAPPER_NAMESPACE);
    }



    @Override
    public List<TblDiacrisisFile> getByFkId(Long id) {
        TblDiacrisisFile tblDiacrisisFile=new TblDiacrisisFile();
        tblDiacrisisFile.setDiacrisisId(id);
        List<TblDiacrisisFile> List= (List<TblDiacrisisFile>) query(DIACFILE_MAPPER_NAMESPACE + "getByFkId", tblDiacrisisFile);
        return List;
    }

    @Override
    public ResponseEntity<byte[]> getFile(String fileCode) {

        TblDiacrisisFile tblDiacrisisFile = get(DIACFILE_MAPPER_NAMESPACE + "getByFlieCode", fileCode);
        tblDiacrisisFile.setFileDownloadNo(tblDiacrisisFile.getFileDownloadNo()+1);
        update(DIACFILE_MAPPER_NAMESPACE+"update",tblDiacrisisFile);
        String filePath=tblDiacrisisFile.getFileAddress();
        String fileName = tblDiacrisisFile.getFileName();
        return  commonFileService.getFile(filePath,fileName);
    }


}
